home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / maxs / dfbv13.lha / dfb / Developers / dfbaddfile.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  3KB  |  116 lines

  1. /* DFBAddFile - by A.Leppard - 5/7/96
  2.  
  3.    This demo source code is in the public domain. 
  4.  
  5.    This is one of the series of dfb dos commands, this command adds a file
  6.    to the file base. Use:
  7.    
  8.    dfbaddfile <filename> <description> <section> <uploader> [<alias>]
  9.  
  10.    e.g:
  11.    
  12.    dfbaddfile ram:cdn-new.lha "a new demo" 23 sysop */
  13.  
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include <stdlib.h>
  17. #include <strings.h>
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <dos/dos.h>
  21. #include <dos/dostags.h>
  22. #include "dfb_pragmas.h"
  23. #include "dfb_protos.h"
  24. #include "dfb.h"
  25.  
  26. int    FileSize(char *filename)
  27. {
  28.     BPTR    file;
  29.     int len;
  30.     struct FileInfoBlock *fib;
  31.  
  32.     len=-1;
  33.  
  34.     if(file=Open(filename, MODE_OLDFILE) ) { 
  35.         if(fib=AllocDosObjectTags(DOS_FIB, ADO_FH_Mode)) {
  36.             len = ExamineFH(file, fib) ? fib->fib_Size : -1;
  37.             FreeDosObject(DOS_FIB, fib);
  38.         }
  39.         Close(file);
  40.     }
  41.     return(len);
  42. }
  43.  
  44. /* Returns pointer to file name from path & file name */
  45.  
  46. char *StripPath(char *source)
  47. {
  48.     char *last;
  49.     
  50.     last=source-1;
  51.     
  52.     while(*source!='\0') {
  53.         if(*source==':' || *source=='/')
  54.             last=source;
  55.         source++;
  56.     }
  57.     return(last+1);
  58. }
  59.  
  60. main(int argv, char **argc)
  61. {
  62.     struct    Library    *DfbBase;
  63.     struct    dfbFile    *File, *FileExist, dfbfile;
  64.     struct    dfbFileBase *FileBase;
  65.     
  66.     File=&dfbfile;
  67.     
  68.     if(argv==5 || argv==6) {
  69.         if(DfbBase=OpenLibrary("dfb.library",0)) {
  70.             if(FileBase=OpenFileBase(ATSTART)) {    /* AddFile needs file base open */
  71.                 File->fb_FileSize=FileSize(argc[1]);
  72.                 if(File->fb_FileSize!=-1) {
  73.                     FixTime(File);                /* time/date of upload is now */
  74.                     File->fb_Section=atoi(argc[3]);
  75.                     File->fb_Name=StripPath(argc[1]);                    
  76.                                                 /* get file name from path */            
  77.                     /* Is the file already in the file base ? */
  78.  
  79.                     FileExist=FindFile(0, NULL, File->fb_Name);
  80.                     if(!FileExist) {            /* if it isn't add it... */
  81.                         File->fb_Desc=argc[2];
  82.                         File->fb_Uploader=argc[4];                
  83.                         if(argv==6)File->fb_Alias=argc[5];
  84.                         else
  85.                             File->fb_Alias=NULL;
  86.                         File->fb_Status=0;
  87.                         File->fb_Down=0;
  88.  
  89.                         if(AddFile(FileBase, File))    
  90.                             printf("Can't write to file base, file not added: %s.\n", argc[1]);
  91.                         else
  92.                             printf("Added File: %s\n", argc[1]);
  93.                     }
  94.                     else {                         /* free FindFile file node */
  95.                         printf("Can't add file, file already in file base: %s\n", argc[1]);
  96.                         FreeMem((char *)FileExist, FileExist->fb_Length);
  97.                     }
  98.                 }
  99.                 else
  100.                     printf("Can't open file, file not added: %s\n", argc[1]);
  101.                 CloseFileBase(FileBase);        
  102.             }
  103.             else
  104.                 printf("Can't load file base, file not added: %s\n", argc[1]);                
  105.             CloseLibrary(DfbBase);            
  106.         }
  107.         else
  108.             printf("Can't load dfb.library, file not added: %s\n", argc[1]);
  109.     }
  110.     else {
  111.         printf("DFBAddFile, use: DFBAddFile <filename> <description> <section>\n");
  112.         printf("<uploader> [<alias>], e.g:\n");
  113.         printf("dfbaddfile ram:cdn-new.lha \"latest demo\" 23 Sysop\n");        
  114.     }        
  115. }
  116.